package com.jams.goodox.activity.serve.enterprise;

import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.github.lzyzsd.library.BridgeWebView;
import com.jams.goodox.BaseActivity;
import com.jams.goodox.R;
import com.jams.goodox.entity.resp.MentorIntroduceResp;
import com.jams.goodox.net.RetrofitCallbackListener;
import com.jams.goodox.net.services.EnterpriseService;
import com.jams.goodox.utils.permission.PhoneUtils;
import com.jams.goodox.utils.StringUtils;
import com.jams.goodox.utils.StyleUtil;
import com.jams.goodox.utils.WebViewUtils;

import butterknife.Bind;
import butterknife.OnClick;
import retrofit2.Call;

import static com.jams.goodox.activity.serve.enterprise.EnterpriseMentorActivity.MENTOR;

/**
 * 企业导师介绍
 */
public class EnterpriseMentorIntroduceActivity extends BaseActivity {

    @Bind(R.id.sdv_icon)
    SimpleDraweeView sdvIcon;
    @Bind(R.id.tv_mentor_name)
    TextView tvMentorName;
    @Bind(R.id.tv_job_tittle)
    TextView tvJobTittle;
    @Bind(R.id.tv_company)
    TextView tvCompany;
    @Bind(R.id.rl_enterprise)
    RelativeLayout rlEnterprise;
    @Bind(R.id.tv_phone)
    TextView tvPhone;
    @Bind(R.id.wv_mentor)
    BridgeWebView wvMentor;
    /**
     * 导师电话
     */
    private String phone = "";


    @Override
    protected int getLayoutId() {
        return R.layout.activity_enterprise_mentor_introduce;
    }

    @Override
    protected void init() {
        StyleUtil.titleBackKey(this, "详情");
        getMentorData(StringUtils.newString(getIntent().getStringExtra(MENTOR)));
    }


    @OnClick(R.id.tv_phone)
    public void onViewClicked() {
        PhoneUtils phoneUtils = new PhoneUtils(mContext);
        phoneUtils.makeCall(StringUtils.newString(tvMentorName.getText().toString().trim()),phone);
       /* Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phone));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);*/
    }

    /**
     * 获取导师信息
     **/
    private void getMentorData(String id) {
        showLoading();
        enqueue(createCallService(EnterpriseService.class).getMentorById(id), new RetrofitCallbackListener<MentorIntroduceResp>() {
            @Override
            public void onSuccess(Call<MentorIntroduceResp> call, MentorIntroduceResp result) {
                misLoading();
                try {
                    tvPhone.setVisibility(View.VISIBLE);//网络请求成功后电话按钮显示
                    phone = result.data.connection;
                    sdvIcon.setImageURI(result.data.photo);
                    tvMentorName.setText(result.data.name);
                    tvJobTittle.setText(result.data.position);
                    tvCompany.setText(result.data.company);
                    WebViewUtils.setWebOnlyBody(wvMentor,StringUtils.newString(result.data.introduce));
                    phone = StringUtils.newString(result.data.connection);
                } catch (Exception e) {
                    e.printStackTrace();
                }

            }

            @Override
            public void onError(String msg) {
                misLoading();
            }
        });
    }


}
